package com.debai.service.Impl;

import com.debai.mapper.PositionMapper;
import com.debai.pojo.Position;
import com.debai.service.PositionService;
import com.debai.util.JwtUtil;
import com.debai.util.Result;
import com.debai.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PositionServiceImpl implements PositionService {
    @Autowired
    private PositionMapper positionMapper;
    @Override
    public int insert(Position position,String token) {
        Map<String, Object> map = JwtUtil.parseToken(token);
        int id = (int) map.get("adminId");
        Integer adminId = (Integer) map.get("adminId");
        position.setAdminId(adminId);
        int i= positionMapper.insert(position);
        return i;
    }

    @Override
    public List<Position> selectAll() {
        List<Position> positions = positionMapper.selectAll();
        return positions;
    }

    @Override
    public int delete(int id) {
        int i=positionMapper.delete(id);
        return i;
    }

    @Override
    public int update(Position position) {
        int i=positionMapper.update(position);
        return i;
    }

    @Override
    public Position selectByName(String positionName) {
        Position position= positionMapper.selectByName(positionName);
        return position;
    }

    @Override
    public Position selectById(int positionId) {
        Position position = positionMapper.selectById(positionId);
        return position;
    }
}
